package com.xjz.exception;

import com.xjz.common.enums.ErrorCode;

/**
 * ClassName: ThrowUtils
 * Package: com.xjz.exception
 * Description:
 *  抛出异常工具类
 * @Author 许小健
 * @Create 2025/8/2 16:09
 * @Version 1.0
 */

public class ThrowUtils {

    /**
     * 条件成立则抛出异常
     * @param condition
     * @param runtimeException
     */
    public static void throwIf(boolean condition,RuntimeException runtimeException) {
        if (condition) {
            throw runtimeException;
        }
    }

    /**
     * 条件成立则抛出异常
     * @param condition
     * @param errorCode
     */
    public static void throwIf(boolean condition, ErrorCode errorCode) {
        throwIf(condition,new BusinessException(errorCode));
    }

    /**
     * 条件成立则抛出异常
     * @param condition
     * @param errorCode
     * @param message
     */
    public static void throwIf(boolean condition, ErrorCode errorCode, String message) {
        throwIf(condition,new BusinessException(errorCode,message));
    }
}
